package mest.controller.LGF.WarehouseWorkFinish;

import mest.VO.LGF.WarehouseWorkFinish.warehouse_productjob_workfinish_recordVO;
import mest.entity.User;
import mest.entity.warehouse_productjob_purchase_record;
import mest.entity.warehouse_productjob_workfinish_record;
import mest.service.LGF.WarehouseWorkFinish.IWarehouseWorkFinsihService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-12-20 21:41
 */
//Model是属于请求域
    //           @RequestMapping(value="/one",params = "method=a")
   //           @RequestMapping(value="/two1",produces = {"application/json;charset=utf-8","text/plain;charset=utf-8"})
    //参数:@RequestParam(value = "b",required = false,defaultValue = "握草尼玛")
    //         @RequestBody String(str) 输出:userCode=admin&userPassword=1234567
    //          @SessionAttributes({"a","b","c"}) 自动把该controller下所有返回页面的属性的作用域改成session
    //          @ModelAttribute标注一个方法时，指定每次跳入某个路径时该方法先执行
@CrossOrigin
@RestController
@RequestMapping(value="/warehouse_workfinish")
public class WarehouseWorkFinishController {

    @Resource
    private IWarehouseWorkFinsihService iwws;

    @RequestMapping(value="/baseSelectNofinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectNofinish(int page, int limit){
        Map map = iwws.baseSelectNofinish(page, limit);
        System.out.println(map);
        return map;
    }


    @RequestMapping(value="/baseSelectFinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectFinish(int page,int limit){
        Map map = iwws.baseSelectFinish(page, limit);
        return map;
    }


    @RequestMapping(value="/selectWorkFinishDetail", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map selectWorkFinishDetail(int wwId,int page,int limit){
        Map map = iwws.selectWorkFinishDetail(wwId,page, limit);
        return map;
    }
    @RequestMapping(value="/selectWorkFinishPastRecord", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map selectWorkFinishPastRecord(int wpwId,int page,int limit){
        Map map = iwws.selectWorkFinishPastRecord(wpwId,page, limit);
        return map;
    }

//    addRecord
        @PostMapping(value="/addRecord", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
        public String addRecord(warehouse_productjob_workfinish_recordVO wpwr, HttpServletRequest request){

            User user = (User) request.getSession().getAttribute("user");
            wpwr.setEfId(user.getUserId());

            System.out.println(wpwr);
            int i = iwws.addRecord(wpwr);

            if(i == -2){
                return   "服务器异常";
            }else if(i == -1){
                return "插入失败";
            }else if(i>0){
                return "插入成功";
            }

            return "未知错误，请联系管理员";
        }

    @RequestMapping(value="/finish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String finish(int wwId,int finishStatus){

        int i = iwws.updateByWWId(wwId,finishStatus);
        if(i == -2){
            return   "服务器异常";
        }else if(i == -1){
            return "更新失败";
        }else if(i>0){
            return "更新成功";
        }
        return "未知错误，请联系管理员";
    }
}
